﻿@{
    ViewBag.Title = "首页";
    Layout = "~/Views/MasterPage.cshtml";
    ViewBag.FirstPage = "首页";
    ViewBag.LastPage = "快捷办公";
}

<script src="~/Scripts/jquery-3.4.1.min.js"></script>
<script src="/Source/Highcharts/code/highcharts.js"></script>
<script src="/Source/Highcharts/code/modules/exporting.js"></script>
<script src="/Source/Highcharts/code/modules/export-data.js"></script>
<script src="~/Source/layui/layui.all.js"></script>
<script src="~/Source/layui/layui.js"></script>
<link href="~/Source/layui/css/layui.css" rel="stylesheet" />

<script type="text/javascript">
    $(function () {

        $.post("/Main/GetJsonArray", {}, function (returnData) {
            //console.log(returnData)

            var jsonData = eval(returnData);
            //console.log(jsonData)
            Highcharts.chart('container', {
                chart: {
                    plotBackgroundColor: null,
                    plotBorderWidth: null,
                    plotShadow: false,
                    type: 'pie'
                },
                title: {
                    text: '部门分布图'
                },
                tooltip: {
                    //pointFormat: '<b>{point.name}</b>: {point.data.y}'
                },
                plotOptions: {
                    pie: {
                        allowPointSelect: true,
                        cursor: 'pointer',
                        dataLabels: {
                            enabled: true,
                            format: '{point.name}',
                            style: {
                                color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
                            }
                        }
                    }
                },
                series:
                    [{
                        name: '人数',
                        colorByPoint: true,
                        data:  jsonData
                    }]
            });
        });
        $("#btnOK").click(function () {
            $.post("/Punch/PunchClock", {}, function (returnData) {
                layer.alert(returnData.Message);
                setInterval(function () {
                    window.location.reload();
                }, 1500);
            });
        });
       
    })
		</script>


<div class="am-g">
    <div class="am-u-md-6">
        <div class="am-panel am-panel-default">
            <div class="am-panel-hd am-cf" data-am-collapse="{target: '#collapse-panel-1'}"><b>@DateTime.Now.Month</b>月考勤记录<span class="am-icon-chevron-down am-fr"></span></div>
            <div class="am-panel-bd am-collapse am-in" id="collapse-panel-1">

                <button style="color: #0094ff; font-size: large;cursor:pointer" id="btnOK">快速打卡</button>
                <br />
                <table style="width:500px;">
                    <tbody>
                        <tr>
                            <th class="am-text-center">员工</th>
                            <th>上班时间</th>
                            <th>下班时间</th>
                            <th>考勤结果</th>
                        </tr>
                         @{
                var workList = BLL.PunchManager.QueryListByWork();
                if (workList.Count != 0)
                {
                    foreach (var item in workList)
                    {
                <tr>
                    <th>
                        @{
                        var user = BLL.EmployeeManager.GetUserBasic(item.UserId);
                        var userName = string.Empty;
                        if (user.Id != 0)
                        {
                            userName = user.RealName;
                        }   
                        }
                        @userName
                    </th>
                    <th>@item.StartTime</th>
                    <th>
                        @{
                        if (item.EndTime == null)
                        {
                            @:
                         }
                        else
                        {
                            @:@Convert.ToDateTime(item.EndTime).ToString("yyyy/M/d HH:mm:ss")
                                                                                                                                                                                                                                                                                                                                                                                                                                    }  
                        }

                    </th>
                    <th>
                        @{
                        var punchEntity = BLL.PunchManager.QueryList().Where(p=>p.Id==item.PunchCardId).FirstOrDefault();
                        if (punchEntity != null)
                        {
                            if (item.StartTime != null && item.EndTime != null)
                            {
                                if (Convert.ToDateTime(item.StartTime.ToString("HH:mm:ss")) <= Convert.ToDateTime(punchEntity.time1) && Convert.ToDateTime(Convert.ToDateTime(item.EndTime).ToString("HH:mm:ss")) >= Convert.ToDateTime(punchEntity.time2))
                                {
                            @:<span class="am-badge am-badge-success">考勤正常</span>
                                }
                                else if (Convert.ToDateTime(item.StartTime.ToString("HH:mm:ss")) > Convert.ToDateTime(punchEntity.time1) && Convert.ToDateTime(Convert.ToDateTime(item.EndTime).ToString("HH:mm:ss")) >= Convert.ToDateTime(punchEntity.time2))
                                {
                            @:<span class="am-badge am-badge-danger">迟到</span>
                                }
                                else if (Convert.ToDateTime(item.StartTime.ToString("HH:mm:ss")) <= Convert.ToDateTime(punchEntity.time1) && Convert.ToDateTime(Convert.ToDateTime(item.EndTime).ToString("HH:mm:ss")) < Convert.ToDateTime(punchEntity.time2))
                                {
                            @:<span class="am-badge">早退</span>
                                }
                                else if (Convert.ToDateTime(item.StartTime.ToString("HH:mm:ss")) > Convert.ToDateTime(punchEntity.time1) && Convert.ToDateTime(Convert.ToDateTime(item.EndTime).ToString("HH:mm:ss")) < Convert.ToDateTime(punchEntity.time2))
                                {
                            @:<span class="am-badge">迟到+早退</span>
                                }
                                else if (item.StartTime <= Convert.ToDateTime(punchEntity.time1) && item.EndTime == null)
                                {
                            @:<span class="am-badge">下午旷工</span>
                                }

                            }
                        }   
                            
                        }


                    </th>
                    
                </tr>
                    }
                }
            }
                    </tbody>
                </table>
            </div>
        </div>
        @* 图形报表 *@
        @{
            var user2 = Session["info"] as Model.OA_UserAccount;
            if(user2!=null)
            {
              if(user2.IsSuper){
                
              }
            }  
          }

        <div class="am-panel am-panel-default">
            <div class="am-panel-hd am-cf" data-am-collapse="{target: '#collapse-panel-3'}">
                数据报表
                <span class="am-icon-chevron-down am-fr"></span>

            </div>
            <div class="am-panel-bd am-collapse am-in" id="collapse-panel-3">
                <div id="container" style="min-width: 310px; height: 400px; max-width: 600px; margin: 0 auto"></div>
            </div>
        </div>
    </div>
    <div class="am-u-md-6">
        <div class="am-panel am-panel-default">
            <div class="am-panel-hd am-cf" data-am-collapse="{target: '#collapse-panel-2'}">
                本月入职人员
                <span class="am-icon-chevron-down am-fr"></span>

            </div>
            <div id="collapse-panel-2" class="am-in">
                <table class="am-table am-table-bd am-table-bdrs am-table-striped am-table-hover">
                    <tbody>
                        <tr>
                            <th class="am-text-center">员工</th>
                            <th>入职日期</th>
                        </tr>
                        @{
                            var empList = BLL.EmployeeManager.QueryEmpListByMonth(DateTime.Now.Month).OrderByDescending(u => u.InsertTime).Take(5).ToList();
                            if (empList.Count != 0)
                            {
                                foreach (var item in empList)
                                {
                            <tr>
                                <td class="am-text-center">@item.RealName</td>
                                <td>@item.InsertTime.ToString("yyyy-MM-dd")</td>
                            </tr>
                                }
                            }   
                        }
                    </tbody>
                </table>
            </div>
        </div>
    </div>


</div>
